<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>预算成本设计详情</title>
    <link href="/res/css/respective/priceAsk/buyer.css" rel="stylesheet">
    <script src="/res/js/common/jquery.1.9.1.min.js"></script>
    <script src="/res/js/common/jquery.ellipsis.js"></script>
</head>
<body>
<div class="warp">
[#include "/front/common/front_headAzt.html"]
    <div class="backcontent">
    [#include "/front/common/front_leftAzt.html"]
        <div class="back-main">
            <div class="mainContent">
                <div class="mainContentWhite">
                    <h1>预算成本详情</h1>
                    <label class="opDetail" style="text-align: right; float: right;"> <a href="/enquiry/project/detail/p/${budgets.enqEnquiry.projectId}/t/3">返回项目</a> </label>
                    <hr>
                    <h2>基本信息</h2>
                    <div class="baseInfo">
                        <div>
                            <dfn> 询价名称：<span class="ellipsis">[#if budgets.enqEnquiry??]${budgets.enqEnquiry.enquiryName!}[/#if]</span> </dfn> <dfn>
                            发布公司：<span>[#if budgets.enqEnquiry??]${budgets.enqEnquiry.companyName!}[/#if]</span> </dfn>
                        </div>
                        <div>
                            <dfn> 项目名称：<span>[#if budgets.enqEnquiry??]${budgets.enqEnquiry.enqProject.projectName!}
												[/#if]</span> </dfn>
                        </div>
                        <div>

                            <dfn> 客户名称：<span>[#if budgets.enqEnquiry??]${budgets.enqEnquiry.enqProject.customerName!}[/#if]</span> </dfn>

                            <dfn> 项目所在地：<span>
                            [#if budgets.enqEnquiry??]
														${budgets.enqEnquiry.enqProject.getAddressName("-")}
												   	[/#if]
												 </span> </dfn>

                        </div>
                        <div>
                            <dfn> 是否含税：<span>[#if budgets.enqEnquiry??][#if budgets.enqEnquiry.taxPrice==3]不含税[#else]含税 ${(budgets.enqEnquiry.taxInstro)!0}% [/#if] [/#if]</span> </dfn>

                            <dfn> 是否含运费：<span>[#if budgets.enqEnquiry??]${(budgets.enqEnquiry.shipPrice==1)?string("含运费","不含运费")!}[/#if]</span> </dfn>

                        </div>
                        <div>
                            <dfn> 质保要求：<span>[#if budgets.enqEnquiry??]${budgets.enqEnquiry.quality!}年[/#if]</span> </dfn>

                        [#if budgets.enqEnquiry?? && budgets.enqEnquiry.attachfile?? ]
                            <dfn> 项目资料：<span><a href="[#if budgets.enqEnquiry??]${budgets.enqEnquiry.attachfile!} [/#if]">附件下载</a></span> </dfn>
                        [/#if]
                        </div>
                    </div>
                    <hr style="margin-bottom: 15px;">
                    <div class="othNed">
                        <label style="color: #999999">其他要求：</label>
                    [#if budgets.enqEnquiry??]${budgets.enqEnquiry.otherRemarks!}[/#if]
                    </div>

                    <h2>预算清单
                        <small class="itermTip">
                            <em style="vertical-align: middle;">供应商筛选：</em>
                            <div class="ppSelect" style="display: inline-block;background: url(/res/images/checkBoxRadio/blueSelect_03.jpg) right center no-repeat;height: 20px;width: auto;">
                                <select onchange="sosuo()" id="so_companyname" style="height: 100%; border: none;background: none;padding-right: 25px;width: auto;">
                                    <option value="0">所有供应商</option>
                                [#list budgets.companys as company]
                                    <option value="${company.companyId}">${company.companyName}</option>
                                [/#list]
                                </select>
                            </div>
                        </small>
                    </h2>
                    <table class="table noBorder">
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" onclick="allSelect(this)"/> 全选
                            </th>
                            <th>供应商</th>
                            <th>产品类目</th>
                            <th>商品名称</th>
                            <th>品牌</th>
                            <th>型号</th>
                            <th>数量</th>
                            <th>单位</th>
                            <th>单价</th>
                            <th>技术参数</th>
                            <th>小计</th>
                        </tr>
                        </thead>
                        <tbody>
                        <!--默认显示8行-->
                        [#list budgets.detailList as budget]
                        <tr class="budget budget_${budget.companyId}">
                            <td>
                                <input onclick="calculate(true)" value="${budget.id}" attq="${budget.quoteId}" class="budgetclass" attu="${budget.unitprice}" type="checkbox"/>
                            </td>
                            <td>${budget.companyName}</td>
                            <td>${budget.categoryName}</td>
                            <td>${budget.productName}</td>
                            <td>${budget.brand!}</td>
                            <td>${budget.model!}</td>
                            <td class="quantity quantity_${budget.quoteId}" attid="${budget.id}" attu="${budget.unitprice}" name="quantity" value="${budget.quantity}">${budget.quantity}</td>
                            <td>${budget.unit!}</td>
                            <td>${budget.unitprice?string("currency")}</td>
                            <td>${budget.descr!}</td>
                            <td class="contentBold">${budget.totalPrice?string("currency")}</td>
                        </tr>
                        [/#list]
                        </tbody>
                        <tfoot>
                        <tr class="tableBorde">
                            <td class="fenye" colspan="11" style="text-align: right; background: #f8f8f8; padding: 30px 15px;">
                                清单总价：&nbsp;&nbsp;&nbsp;
                                <span id="totalPrice" class="contentBold" style="font-size: 18px; padding-right: 20px;vertical-align: middle;">${budgets.totalPrice?string("currency")}
											</span>
                            </td>
                        </tr>
                        </tfoot>
                    </table>

                    <div style="margin-top: 30px;height: 45px;">
                        <button onclick="download(${budgetid!})" class="backButt" type="button">下载完整清单</button>
                    [#--[#if budgets.enqBudget.userId == userid ]--]
                        <button  onclick="postToEnquiry(${budgetid!})"  class="backButt" style="float: right;" type="button">转发采购询价</button>
                    [#--[/#if]--]
                    </div>
                </div>
            </div>
        </div>
        <!-- 底部菜单-->
    [#include "/front/common/front_footerAzt.html"]
    </div>

</div>
<script src="/res/js/buyer/buyer.js"></script>
<script src="/res/js/common/common.js"></script>
<script src="/res/js/common/jQuery.plusready.js"></script>
<script src="/res/third/layer/layer.js"></script>
<script src="/res/third/layer/layer.extends.js"></script>
<script type="text/javascript">
$(function(){
	$(".ellipsis").ellipsis({maxWidth:290,maxLine:1});
});
    /*下载*/
    function download(budgetid) {
        location.href = "/enquiry/budget/detail/download/" + budgetid;
    }


    function allSelect(obj) {
        $(".budgetclass").each(function (i) {
            $(this)[0].checked = $(obj).is(":checked");
        });
        calculate(true);
    }


    //计算选择的价格
    function calculate(ischecked) {

        var price = 0.0;
        $(".budgetclass").each(function () {
            if (!$(this).is(":checked")) {
                if (ischecked) {
                    return true;
                }
            }
            var uprice = $(this).attr("attu");
            var quantity = $(this).parents("tr").find(".quantity").attr("value");
            price = price + parseFloat(quantity) * parseFloat(uprice);
        });
        if (ischecked) {
            $("#choosedPrice").text($.my.currency(price, true));
        } else {
            $("#totalPrice").text($.my.currency(price, true));
        }

    }


    function sosuo() {
        var v = $("#so_companyname").val();
        if (v == 0) {
            $(".budget").show();
        } else {
            $(".budget").hide();
            $(".budget_" + v).show();
        }
    }

    function postToEnquiry(budgetid) {
        layer.post({
            url: "/enquiry/budget/to/purchase",
            data: {budgetid: budgetid},
            success: function (data) {
                if(data.success){
                    location.href ="/enquiry/purchase/choose/"+data.obj;
//                    location.href="/enquiry/purchase/create/"+data.obj;
                }else{
                    layer.msgShort(data.msg);
                }
            }

        }, "正在提交");
    }

    //下单
    function gobuy(enquiryid) {
        var ids = [];
        var attqs = [];
        $(".budgetclass:checked").each(function () {
            ids.push($(this).val());
            var quoteid = $(this).attr("attq");
            if ($.inArray(quoteid, attqs) == -1) {
                attqs.push(quoteid);
            }
        });

        if (ids.length == 0) {
            layer.msgShort("至少选择一个商品购买!");
            return false;
        }

        var d = [];
        attqs.forEach(function (v) {
            var o = {};
            o.quoteId = v;
            o.items = [];
            $(".quantity_" + v).each(function () {
                var itemid = $(this).attr("attid");
                var value = $(this).attr("value");
                if ($.inArray(itemid, ids) != -1) {
                    var oc = {};
                    oc.itemId = itemid;
                    oc.quantity = value;
                    o.items.push(oc);
                }
            });
            d.push(o);
        });
        $.my.postForm("/order/submit/quote", {enquiryId: enquiryid, item: JSON.stringify(d)});
        //location.href="/order/submit?enquiryId="+enquiryid+"&item="+JSON.stringify(d);
    }
</script>
</body>
</html>
